<script>
	import Vue from 'vue'
	export default {
		onLaunch: function() {
			const that = this
			uni.getSystemInfo({
				success: function(e) {
					let StatusBar, CustomBar, Custom
					// #ifndef MP
					StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						CustomBar = e.statusBarHeight + 50;
					} else {
						CustomBar = e.statusBarHeight + 45;
					};
					// #endif
					
					// #ifdef MP-WEIXIN
					StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Custom = custom;
					CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		
					
					// #ifdef MP-ALIPAY
					StatusBar = e.statusBarHeight;
					CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
					that.$store.commit('SET_SYSTEM_INFO', {
						StatusBar: StatusBar,
						CustomBar: CustomBar,
						Custom: Custom,
						uniPlatform: e.uniPlatform
					})
				}
			})
			// 获取综合计税规则
			this.$store.dispatch('getTaxRate')
			// 判断是否存在更新
			this.getUp()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			getUp: function() {
				const updateManager = uni.getUpdateManager() // 小程序版本更新管理器
				updateManager.onCheckForUpdate(res => { // 检测新版本后的回调
					if (res.hasUpdate) { // 如果有新版本提醒并进行强制升级
						uni.showModal({
							content: '新版本已经准备好，是否重启应用？',
							showCancel: false,
							confirmText: '确定',
							confirmColor: '#3e90fa',
							success: res => {
								if (res.confirm) {
									updateManager.onUpdateReady(res => { // 新版本下载完成的回调
										updateManager.applyUpdate() // 强制当前小程序应用上新版本并重启
									})
			
									updateManager.onUpdateFailed(res => { // 新版本下载失败的回调
										// 新版本下载失败，提示用户删除后通过冷启动重新打开
										uni.showModal({
											content: '下载失败，请删除当前小程序后重新搜索打开',
											showCancel: false,
											confirmText: '我知道了'
										})
									})
								}
							}
						})
					}
				})
			},
		}

	}
</script>

<style>
	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "common/iconfont/iconfont.css";
	@import "common/common.css";
</style>
